<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--退货信息-->
			<view class="detail-item">
				<uni-section title="退货信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">退货单号：<text>{{info.number}}</text></view>
					<view class="detail-text">采购付款(退款)编号：<text>{{info.purchasePaymentNumber}}</text></view>
					<view class="detail-text">仓库名称：<text>{{info.warehouseName}}</text></view>
					<view class="detail-text">供应商名称：<text>{{info.supplierName}}</text></view>
					<view class="detail-text">创建人：<text>{{info.createUserName}}</text></view>
					<view class="detail-text">状态：<uni-tag size="small" :class="`purchase-return-status-${info.status}`" :text="arrText(purchaseReturnStatusList, info.status)" /></view>
					<view class="detail-text" v-if="checkPermi(['zhouyz:purchaseReturn:price'])">退货金额：<text>{{info.returnMoney}}</text></view>
					<view class="detail-text">操作时间：<text>{{info.createTime}}</text></view>
					<view class="detail-text">退货说明：<text>{{info.remark}}</text></view>
				</view>
			</view>
			
			<!--退货商品-->
			<view class="detail-item" v-if="checkPermi(['zhouyz:purchaseReturnProduct:list'])">
				<uni-section title="退货商品" type="line"></uni-section>
				<view class="detail-content table">
					<ty-table
						:data="tableList"
						:columns="columns"
						:sortable="true"
						:cellClassName="() => 'table-cell'"
						:headerCellClassName="() => 'table-cell'"
						:rowClassName="() => 'table-row'"
						stripe
						border>
						<template v-slot:left="{ row }">
							<view class="table-cell">
								<view class="table-td-row">
									商品名称：
									<text class="table-td-text">{{row.productName}}</text></view>
								<view class="table-td-row">
									批次号：
									<text class="table-td-text">{{row.batchNumber}}</text></view>
								<view class="table-td-row">
									采购订单编号：
									<text class="table-td-text">{{row.purchaseOrderNumber}}</text></view>
							</view>
						</template>
						<template v-slot:right="{ row }">
							<view class="table-cell">
								<view class="table-td-row" v-if="checkPermi(['zhouyz:purchaseReturn:price'])">
									采购价格：
									<text class="table-td-text">{{row.purchasePrice}}</text></view>
								<view class="table-td-row">
									退货数量：
									<text class="table-td-text">{{row.number}}</text></view>
								<view class="table-td-row">
									规格单位：
									<text class="table-td-text">{{row.unit}}</text></view>
							</view>
						</template>
					</ty-table>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { purchaseReturnDetail, purchaseReturnProduct } from "@/api/erp_api/purchase"
import { copyText, arrText } from '@/utils/ty.js';
import useUserStore from '@/store/modules/user'
import { purchaseReturnStatusList } from '@/utils/config.js'

	const userStore = useUserStore()
	onLoad((option) => {
		if (option.id) {
			id.value = option.id
			getDetail()
			getList()
		}
	})
	
	// 数据查询
	const id = ref('')
	const info = ref({})
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		purchaseReturnDetail(params).then(res => {
			info.value = res.data || {}
			isLoading.value = false
			uni.hideLoading()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
	// 退货商品
	const columns = ref([
		{ title: '商品信息', key: 'left'},
		{ title: '退货信息', key: 'right', width: '260rpx' }
	])
	
	const tableList = ref([])
	
	const getList = () => {
		purchaseReturnProduct({
			id: id.value
		}).then(res => {
			tableList.value = res.data || []
	  })
	}
</script>

<style scoped lang="scss">
.detail-text-integral {
	margin-left: 20rpx;
}
.detail-text-banners {
	margin-left: -10rpx;
}
.detail-text-banner {
	margin: 0 10rpx 10rpx;
}
.detail-text-video {
	width: 100%;
	height: 250rpx;
}
</style>
